/*
 * @Author: your name
 * @Date: 2021-11-10 08:34:30
 * @LastEditTime: 2021-12-17 14:14:31
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \li-yuwei\egg-example\app\service\login.js
 */

const Service = require("egg").Service;
const timeFormart = require("../extends/timeFormart");
class OrderService extends Service {
    //获取列表
    async getOrderList() {
            const { ctx, app } = this;
            let res = await app.mysql.select("order");
            res = res.map((item, index) => {
                return {
                    ...item,
                    key: index + 1,
                };
            });
            return res;
        }
        //搜索
    async searchOrderList() {
            const { ctx, app } = this;
            const { ordertype, keyword } = ctx.query;
            let res = await app.mysql.select("order");
            if (ordertype !== undefined) {
                res = res.filter((item) => item.ordertype === ordertype);
            }
            if (keyword) {
                res = res.filter((item) => item.telephone.includes(keyword) || item.serial.includes(keyword) || item.username.includes(keyword));
            }
            return res;
        }
        //删除
    async delOrderList() {
        const { ctx, app } = this;
        const { id } = ctx.params;
        const res = await app.mysql.delete("order", { id });
        return res;
    }
}
module.exports = OrderService;